<?php
/**
 * Created by PhpStorm.
 * User: yinnannan
 * Date: 16/1/19
 * Time: 上午5:15
 */
class pageconfig  {
    public function getAll(){
        return DB::select('name,id,type,content')->from('syspageconfig')->order_by("sort",'asc')->execute()->as_array();
    }
    public function getList(){
        $query = DB::select('*')->from('syspageconfig')->execute()->as_array();
        $count = DB::query(Database::SELECT,
	         'select count(1) from syspageconfig   ')->execute()->as_array();
		$data['total']=$count[0]['count(1)'];
		$data['rows']=$query;
		return $data;
    }

    public function insert($parm){

        Cache::instance('file')->delete_all();
        $result = DB::select('*')->from('syspageconfig')->where("type","=",$parm['type'])->execute()->as_array();
        if(count($result) <$parm['count']){
            DB::insert("syspageconfig",array('name','content','sort','type'))
                ->values(array($parm['name'],$parm['content'],$parm['sort'],$parm['type']))
                ->execute();
        }else{
            DB::update("syspageconfig")->set(array('name'=>$parm['name'],'content'=>$parm['content'],'sort'=>$parm['sort'],'type'=>$parm['type']))->where('id','=',$result[0]['id'])->execute();

        }

    }

    
}